#include "StdAfx.h"
#include "CommonFun.h"
#include "CommonData.h"




void Msg(TCHAR *szFormat, ...)
{
	TCHAR szBuffer[1024];  // Large buffer for long filenames or URLs
	const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]);
	const int LASTCHAR = NUMCHARS - 1;

	// Format the input string
	va_list pArgs;
	va_start(pArgs, szFormat);

	// Use a bounded buffer size to prevent buffer overruns.  Limit count to
	// character size minus one to allow for a NULL terminating character.
	(void)StringCchVPrintf(szBuffer, NUMCHARS - 1, szFormat, pArgs);
	va_end(pArgs);

	// Ensure that the formatted string is NULL-terminated
	szBuffer[LASTCHAR] = TEXT('\0');

	// Display a message box with the formatted string
	MessageBox(NULL, szBuffer, TEXT("PlayWnd Sample"), MB_OK);
}

void GetFilename(TCHAR *pszFull, TCHAR *pszFile)
{
	int nLength;
	TCHAR szPath[MAX_PATH]={0};
	BOOL bSetFilename=FALSE;

	// Strip path and return just the file's name
	(void)StringCchCopy(szPath, MAX_PATH, pszFull);
	szPath[MAX_PATH-1] = 0;

	nLength = (int) _tcslen(szPath);

	for (int i=nLength-1; i>=0; i--)
	{
		if ((szPath[i] == '\\') || (szPath[i] == '/'))
		{
			szPath[i] = '\0';
			lstrcpyn(pszFile, &szPath[i+1], MAX_PATH);
			bSetFilename = TRUE;
			break;
		}
	}

	// If there was no path given (just a file name), then
	// just copy the full path to the target path.
	if (!bSetFilename)
		(void)StringCchCopy(pszFile, MAX_PATH, pszFull);

	pszFile[MAX_PATH-1] = 0;        // Ensure null-termination
}

BOOL IsWindowsMediaFile(LPTSTR lpszFile)
{
	TCHAR szFilename[MAX_PATH];

	// Copy the file name to a local string and convert to lowercase
	(void)StringCchCopy(szFilename, NUMELMS(szFilename), lpszFile);
	szFilename[MAX_PATH-1] = 0;
	_tcslwr(szFilename);

	if (_tcsstr(szFilename, TEXT(".asf")) ||
		_tcsstr(szFilename, TEXT(".wma")) ||
		_tcsstr(szFilename, TEXT(".wmv")))
		return TRUE;
	else
		return FALSE;
}